<template>
  <XForm ref="form" class="mr-[230px]" :formData="data" :fieldList="fieldList" :options="formOption" :rules="rules" />
  <!-- <VForm class="mr-[230px]" ref="form" :model="data" :fieldList="fieldList" :options="formOption" :rules="rules" /> -->
</template>

<script setup>
import XForm from "@/components/XForm/index.vue"
const props = defineProps({
  country: {
    type: Array,
    default: () => [],
  },
  data: {
    type: Object,
    default: () => ({}),
  },
})
const form = ref()

const publicStyle = { style: { width: "320px" } }
const fieldList = ref([
  { type: "title", label: "寄件人信息" },
  { field: "sender_company", label: "寄件单位", ...publicStyle },
  { field: "sender_name", label: "联系人", ...publicStyle },
  { field: "sender_phone", label: "联系电话", ...publicStyle },
  { field: "sender_email", label: "邮箱", ...publicStyle },
  {
    field: "sender_tax_id",
    label: "寄件人税号",
    ...publicStyle,
    tooltip: "如：IOSS税号，VAT税号，VOEC税号",
  },
  { type: "br" },
  {
    field: "sender_country",
    label: "国家/地区",
    type: "select",
    ...publicStyle,
    options: { data: [] },
  },
  { field: "sender_province", label: "州/省", style: { width: "240px" } },
  { field: "sender_city", label: "城市", style: { width: "240px" } },
  { field: "sender_region", label: "区/县", style: { width: "240px" } },
  { field: "sender_zip_code", label: "邮编", ...publicStyle },
  { field: "sender_door_num", type: "inputNumber", label: "门牌号", ...publicStyle },
  { field: "sender_preferred_address", label: "详细地址", itemStyle: { width: "100%" }, full: true },
  { field: "sender_secondary_address", label: "详细地址2", itemStyle: { width: "100%" }, full: true },
])

const rules = reactive({})

watch(props, (val) => {
  const { country } = val
  if (country && country.length) {
    const _index = fieldList.value.findIndex((n) => n.field === "sender_country")
    fieldList.value[_index].options.data = country
  }
})

const formOption = ref({ inline: true, labelPosition: "top" })

defineExpose({ form })
</script>

<style lang="scss" scoped></style>
